package com.nio;

import java.nio.ByteBuffer;

public class BufferTester {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ByteBuffer buf = ByteBuffer.allocate(128);
		
		try{
			while(true){
				int c = System.in.read();
				if(c == -1)
					break;
				//buf.putInt(c);
				buf.put((byte)c);
				if(c == '\n'){
					buf.flip();
					//byte[] bytes = new byte[buf.position()];
					byte[] bytes = new byte[buf.limit()];
					buf.get(bytes);
					//bytes = buf.array();
					System.out.println(new String(bytes));
					//System.out.println(buf.toString());
					buf.clear();
				}
			}
		}catch (Exception e) {
			e.printStackTrace();
		}

	}

}
